package ggkeno

import (
	"github.com/shopspring/decimal"
	"wzgames/internal/model/gkindp"
	"wzgames/internal/secure/rng"
)

type KenoGift struct {
	totalCell int
	open      int
}

func (gf *KenoGift) Init(cfg *gkindp.KenoConfig) {
	gf.totalCell = 36
	gf.open = 10
}

func (gf *KenoGift) Update(cfg *gkindp.KenoConfig) {

}

func (gf *KenoGift) Calculate(servSeed, clientSeed string) []int32 {
	var holes []int32
	for i := 0; i < gf.totalCell; i++ {
		holes = append(holes, int32(i+1))
	}

	nums := rng.CalculateHash(servSeed, clientSeed, rng.ChunkSize, 10)
	var ret []int32
	for i := 0; i < gf.open; i++ {
		l := len(holes)
		idx := decimal.NewFromFloat(nums[i]).Mul(decimal.NewFromInt32(int32(l)))
		index := int(idx.IntPart())
		ret = append(ret, holes[index])
		holes = append(holes[:index], holes[index+1:]...)
	}

	return ret
}
